package com.caow.composebase.http.interceptor

import okhttp3.Interceptor
import okhttp3.Response

/**
 * @Author caow
 * 2022/12/9
 */
class HeaderInterceptor(private val params: Map<String, String>) : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val reqBuilder = chain.request().newBuilder()
        /**
         * 协议头参数
         */
        reqBuilder.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
            .addHeader("Accept-Encoding", "gzip")
            .addHeader("Connection", "keep-alive")
            .addHeader("Accept", "*/*")


        //添加token
//        val userToken: String = LoginMgr.getInstance().getUserToken()
//        if (!TextUtils.isEmpty(userToken)) {
//            reqBuilder.addHeader("token", userToken)
//        }
        /**
         * 各app公用参数
         */
        for (key in this.params.keys) {
            params[key]?.let { reqBuilder.addHeader(key, it) }
            //                LogUtils.i("ReqInterceptor", key);
        }
        return chain.proceed(reqBuilder.build())
    }
}